<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        label {
            text-align: right;
            display: inline-block;
            width: 80px;
        }
        .active {
            background-color: #a0a0a0;
        }
    </style>
</head>

<body>
    <div id="app">
        <p>localStorage.clear() 清空所有</p>
        <p>localStorage.remove(id) 删除指定项</p>
        <p>localStorage.getItem(id) 获取指定项</p>
        <p>localStorage.setItem(id, val) 设置某一项</p>
        <p>信息登记表</p>
        <form>
            <label>尊姓大名</label>
            <input type="text" v-model="user.name">
            <br>
            <label>年龄</label>
            <input type="text" v-model="user.age">
            <br>
            <label>性别</label>
            <!-- 单选多选中的value是发给后台存进数据库的，text是给用户看的 -->
            <input type="radio" v-model="user.sex" value="1">男
            <input type="radio" v-model="user.sex" value="2">女
            <br>
            <label>手机号</label>
            <input type="text" v-model="user.phone">
            <br>
            <label>国籍</label>
            <select v-model="user.gj">
                <option value="0">中国</option>
                <option value="1">大毛</option>
                <option value="2">二毛</option>
                <option value="3">三哥</option>
            </select>
            <br>
            <button type="button" @click="add">add</button>
        </form>
        <hr>
        <table border="1">
            <thead>
                <tr>
                    <th>尊姓大名</th>
                    <th>年龄</th>
                    <th>性别</th>
                    <th>手机号</th>
                    <th>国籍</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(item, index) in userList" :key="index" :class="{active:index%2==0}">
                    <td>{{item.name}}</td>
                    <td>{{item.age}}</td>
                    <td>{{item.sex}}</td>
                    <td>{{item.phone}}</td>
                    <td>{{item.gj}}</td>
                </tr>
            </tbody>
        </table>
    </div>
    <script src="../0511/js/vue.js"></script>
    <script>
        let vm = new Vue({
            el: '#app',
            data: {
                user: {
                    name: '',
                    age: 18,
                    sex: 2,
                    phone: '',
                    gj: 0
                },
                userList: []
            },
            methods: {
                add() {
                    this.userList.push(this.user);
                    console.log(this.user);
                    console.log(this.userList);
                }
            }
        })
    </script>
</body>

</html>